{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "!ls datalab/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test.py\n"
     ]
    }
   ],
   "source": [
    "# 查看个人永久空间文件  list files in your permanent storage\n",
    "!ls /home/tianchi/myspace/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Package                            Version  \n",
      "---------------------------------- ---------\n",
      "absl-py                            0.8.1    \n",
      "alabaster                          0.7.12   \n",
      "anaconda-client                    1.7.2    \n",
      "anaconda-navigator                 1.9.7    \n",
      "anaconda-project                   0.8.3    \n",
      "asn1crypto                         0.24.0   \n",
      "astor                              0.8.0    \n",
      "astroid                            2.2.5    \n",
      "astropy                            3.2.1    \n",
      "atomicwrites                       1.3.0    \n",
      "attrs                              19.1.0   \n",
      "Babel                              2.7.0    \n",
      "backcall                           0.1.0    \n",
      "backports.functools-lru-cache      1.5      \n",
      "backports.os                       0.1.1    \n",
      "backports.shutil-get-terminal-size 1.0.0    \n",
      "backports.tempfile                 1.0      \n",
      "backports.weakref                  1.0.post1\n",
      "beautifulsoup4                     4.7.1    \n",
      "bitarray                           0.9.3    \n",
      "bkcharts                           0.2      \n",
      "bleach                             3.1.0    \n",
      "bokeh                              1.2.0    \n",
      "boto                               2.49.0   \n",
      "Bottleneck                         1.2.1    \n",
      "cachetools                         3.1.1    \n",
      "certifi                            2019.6.16\n",
      "cffi                               1.12.3   \n",
      "chardet                            3.0.4    \n",
      "Click                              7.0      \n",
      "cloudpickle                        1.2.1    \n",
      "clyent                             1.2.2    \n",
      "colorama                           0.4.1    \n",
      "comtypes                           1.1.7    \n",
      "conda                              4.7.10   \n",
      "conda-build                        3.18.8   \n",
      "conda-package-handling             1.3.11   \n",
      "conda-verify                       3.4.2    \n",
      "contextlib2                        0.5.5    \n",
      "cryptography                       2.7      \n",
      "cycler                             0.10.0   \n",
      "Cython                             0.29.12  \n",
      "cytoolz                            0.10.0   \n",
      "dask                               2.1.0    \n",
      "decorator                          4.4.0    \n",
      "defusedxml                         0.6.0    \n",
      "distributed                        2.1.0    \n",
      "docutils                           0.14     \n",
      "entrypoints                        0.3      \n",
      "et-xmlfile                         1.0.1    \n",
      "fastcache                          1.1.0    \n",
      "filelock                           3.0.12   \n",
      "Flask                              1.1.1    \n",
      "future                             0.17.1   \n",
      "gast                               0.2.2    \n",
      "gevent                             1.4.0    \n",
      "glob2                              0.7      \n",
      "google-auth                        1.7.0    \n",
      "google-auth-oauthlib               0.4.1    \n",
      "google-pasta                       0.1.8    \n",
      "greenlet                           0.4.15   \n",
      "grpcio                             1.25.0   \n",
      "h5py                               2.9.0    \n",
      "heapdict                           1.0.0    \n",
      "html5lib                           1.0.1    \n",
      "idna                               2.8      \n",
      "imageio                            2.5.0    \n",
      "imagesize                          1.1.0    \n",
      "importlib-metadata                 0.17     \n",
      "ipykernel                          5.1.1    \n",
      "ipython                            7.6.1    \n",
      "ipython-genutils                   0.2.0    \n",
      "ipywidgets                         7.5.0    \n",
      "isort                              4.3.21   \n",
      "itsdangerous                       1.1.0    \n",
      "jdcal                              1.4.1    \n",
      "jedi                               0.13.3   \n",
      "Jinja2                             2.10.1   \n",
      "joblib                             0.13.2   \n",
      "json5                              0.8.4    \n",
      "jsonschema                         3.0.1    \n",
      "jupyter                            1.0.0    \n",
      "jupyter-client                     5.3.1    \n",
      "jupyter-console                    6.0.0    \n",
      "jupyter-core                       4.5.0    \n",
      "jupyterlab                         1.0.2    \n",
      "jupyterlab-server                  1.0.0    \n",
      "jupyterthemes                      0.20.0   \n",
      "Keras-Applications                 1.0.8    \n",
      "Keras-Preprocessing                1.1.0    \n",
      "keyring                            18.0.0   \n",
      "kiwisolver                         1.1.0    \n",
      "lazy-object-proxy                  1.4.1    \n",
      "lesscpy                            0.13.0   \n",
      "libarchive-c                       2.8      \n",
      "llvmlite                           0.29.0   \n",
      "locket                             0.2.0    \n",
      "lxml                               4.3.4    \n",
      "Markdown                           3.1.1    \n",
      "MarkupSafe                         1.1.1    \n",
      "matplotlib                         3.1.0    \n",
      "mccabe                             0.6.1    \n",
      "menuinst                           1.4.16   \n",
      "mistune                            0.8.4    \n",
      "mkl-fft                            1.0.12   \n",
      "mkl-random                         1.0.2    \n",
      "mkl-service                        2.0.2    \n",
      "mock                               3.0.5    \n",
      "more-itertools                     7.0.0    \n",
      "mpmath                             1.1.0    \n",
      "msgpack                            0.6.1    \n",
      "multipledispatch                   0.6.0    \n",
      "navigator-updater                  0.2.1    \n",
      "nbconvert                          5.5.0    \n",
      "nbformat                           4.4.0    \n",
      "networkx                           2.3      \n",
      "nltk                               3.4.4    \n",
      "nose                               1.3.7    \n",
      "notebook                           6.0.0    \n",
      "numba                              0.44.1   \n",
      "numexpr                            2.6.9    \n",
      "numpy                              1.16.4   \n",
      "numpydoc                           0.9.1    \n",
      "oauthlib                           3.1.0    \n",
      "olefile                            0.46     \n",
      "openpyxl                           2.6.2    \n",
      "opt-einsum                         3.1.0    \n",
      "packaging                          19.0     \n",
      "pandas                             0.24.2   \n",
      "pandocfilters                      1.4.2    \n",
      "parso                              0.5.0    \n",
      "partd                              1.0.0    \n",
      "path.py                            12.0.1   \n",
      "pathlib2                           2.3.4    \n",
      "patsy                              0.5.1    \n",
      "pep8                               1.7.1    \n",
      "pickleshare                        0.7.5    \n",
      "Pillow                             6.1.0    \n",
      "pip                                19.1.1   \n",
      "pkginfo                            1.5.0.1  \n",
      "pluggy                             0.12.0   \n",
      "ply                                3.11     \n",
      "prometheus-client                  0.7.1    \n",
      "prompt-toolkit                     2.0.9    \n",
      "protobuf                           3.10.0   \n",
      "psutil                             5.6.3    \n",
      "py                                 1.8.0    \n",
      "pyasn1                             0.4.7    \n",
      "pyasn1-modules                     0.2.7    \n",
      "pycodestyle                        2.5.0    \n",
      "pycosat                            0.6.3    \n",
      "pycparser                          2.19     \n",
      "pycrypto                           2.6.1    \n",
      "pycurl                             7.43.0.3 \n",
      "pyflakes                           2.1.1    \n",
      "Pygments                           2.4.2    \n",
      "pylint                             2.3.1    \n",
      "pymongo                            3.9.0    \n",
      "pyodbc                             4.0.26   \n",
      "pyOpenSSL                          19.0.0   \n",
      "pyparsing                          2.4.0    \n",
      "pyreadline                         2.1      \n",
      "pyrsistent                         0.14.11  \n",
      "PySocks                            1.7.0    \n",
      "pytest                             5.0.1    \n",
      "pytest-arraydiff                   0.3      \n",
      "pytest-astropy                     0.5.0    \n",
      "pytest-doctestplus                 0.3.0    \n",
      "pytest-openfiles                   0.3.2    \n",
      "pytest-remotedata                  0.3.1    \n",
      "python-dateutil                    2.8.0    \n",
      "pytz                               2019.1   \n",
      "PyWavelets                         1.0.3    \n",
      "pywin32                            223      \n",
      "pywinpty                           0.5.5    \n",
      "PyYAML                             5.1.1    \n",
      "pyzmq                              18.0.0   \n",
      "QtAwesome                          0.5.7    \n",
      "qtconsole                          4.5.1    \n",
      "QtPy                               1.8.0    \n",
      "requests                           2.22.0   \n",
      "requests-oauthlib                  1.3.0    \n",
      "rope                               0.14.0   \n",
      "rsa                                4.0      \n",
      "ruamel-yaml                        0.15.46  \n",
      "scikit-image                       0.15.0   \n",
      "scikit-learn                       0.21.2   \n",
      "scipy                              1.2.1    \n",
      "seaborn                            0.9.0    \n",
      "Send2Trash                         1.5.0    \n",
      "setuptools                         41.0.1   \n",
      "simplegeneric                      0.8.1    \n",
      "singledispatch                     3.4.0.3  \n",
      "six                                1.12.0   \n",
      "snowballstemmer                    1.9.0    \n",
      "sortedcollections                  1.1.2    \n",
      "sortedcontainers                   2.1.0    \n",
      "soupsieve                          1.8      \n",
      "Sphinx                             2.1.2    \n",
      "sphinxcontrib-applehelp            1.0.1    \n",
      "sphinxcontrib-devhelp              1.0.1    \n",
      "sphinxcontrib-htmlhelp             1.0.2    \n",
      "sphinxcontrib-jsmath               1.0.1    \n",
      "sphinxcontrib-qthelp               1.0.2    \n",
      "sphinxcontrib-serializinghtml      1.1.3    \n",
      "sphinxcontrib-websupport           1.1.2    \n",
      "spyder                             3.3.6    \n",
      "spyder-kernels                     0.5.1    \n",
      "SQLAlchemy                         1.3.5    \n",
      "statsmodels                        0.10.0   \n",
      "sympy                              1.4      \n",
      "tables                             3.5.2    \n",
      "tblib                              1.4.0    \n",
      "tensorboard                        2.0.1    \n",
      "tensorflow                         2.0.0    \n",
      "tensorflow-estimator               2.0.1    \n",
      "termcolor                          1.1.0    \n",
      "terminado                          0.8.2    \n",
      "testpath                           0.4.2    \n",
      "toolz                              0.10.0   \n",
      "tornado                            6.0.3    \n",
      "tqdm                               4.32.1   \n",
      "traitlets                          4.3.2    \n",
      "unicodecsv                         0.14.1   \n",
      "urllib3                            1.24.2   \n",
      "vboxapi                            1.0      \n",
      "wcwidth                            0.1.7    \n",
      "webencodings                       0.5.1    \n",
      "Werkzeug                           0.15.4   \n",
      "wheel                              0.33.4   \n",
      "widgetsnbextension                 3.5.0    \n",
      "win-inet-pton                      1.1.0    \n",
      "win-unicode-console                0.5      \n",
      "wincertstore                       0.2      \n",
      "wrapt                              1.11.2   \n",
      "xlrd                               1.2.0    \n",
      "XlsxWriter                         1.1.8    \n",
      "xlwings                            0.15.8   \n",
      "xlwt                               1.3.0    \n",
      "zict                               1.0.0    \n",
      "zipp                               0.5.1    \n"
     ]
    }
   ],
   "source": [
    "# 查看当前kernel下已安装的包  list packages\n",
    "!pip list --format=columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第1章 机器学习简介"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 什么是机器学习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 机器学习的应用场景\n",
    "+ 垃圾邮件识别\n",
    "+ 图像识别\n",
    "+ 人脸识别\n",
    "+ 语音识别\n",
    "+ 数字识别\n",
    "+ 银行发卡和贷款\n",
    "+ 搜索推荐\n",
    "+ 商品推荐\n",
    "+ 金融预测\n",
    "+ 医疗诊断\n",
    "+ 市场分析\n",
    "+ 无人驾驶\n",
    "+ 安全领域\n",
    "+ 自然语言\n",
    "+ 矿产勘查\n",
    "+ 宇宙探索\n",
    "+ 药物研发\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 课程涵盖的内容和理念"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 本课程会成体系地介绍如下的机器学习算法\n",
    "\n",
    "+ kNN\n",
    "+ 线性回归\n",
    "+ 多项式回归\n",
    "+ 逻辑回归\n",
    "+ 模型正则化\n",
    "+ PCA\n",
    "+ SVM\n",
    "+ 决策树\n",
    "+ 随机森林\n",
    "+ 集成学习\n",
    "+ 模型选择\n",
    "+ 模型调试\n",
    "\n",
    "其中最常用的算法是：逻辑回归、决策树和随机森林\n",
    "\n",
    "### 课程的讲解方式\n",
    "\n",
    "+ 深入理解算法基本原理\n",
    "+ 实际使用算法解决真实场景的问题\n",
    "+ 对不同算法进行对比试验\n",
    "+ 对同一算法的不同参数进行对比试验\n",
    "+ 对部分算法底层编写"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 介绍如何使用算法\n",
    "+ 如何评价算法的好坏\n",
    "+ 如何解决过拟合和欠拟合\n",
    "+ 如何调节算法的参数\n",
    "+ 如何验证算法的正确性"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 不仅仅是调库\n",
    "+ 不反对调库。但是在调库的时候应该对概念原理了解\n",
    "+ 深入代码内部，可以帮助我们更好地理解算法\n",
    "+ 更好地理解算法，可以帮助我们更好地选择算法\n",
    "+ 甚至在将来创造新的算法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 这门课希望兼顾\n",
    "+ 算法原理的学习\n",
    "+ 部分算法底层的编写\n",
    "+ scikit-learn机器学习库的使用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 课程所使用的技术栈\n",
    "\n",
    "### 环境\n",
    "\n",
    "+ 语言：Python3\n",
    "+ 框架：Scikit-learn\n",
    "+ 其他：numpy and matplotlib\n",
    "+ IDE : jupyter notebook and PyCharm\n",
    "\n",
    "### 课程使用的数据集\n",
    "\n",
    "> sklearn内置数据集或者通过sklearn可以直接下载的数据集\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第2章 机器学习基础"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.1 机器学习世界的数据\n",
    "\n",
    "+ 数据整体叫数据集(dataset)\n",
    "+ 每一行数据称为一个样本\n",
    "+ 除最后一列，每一列表达样本的一个特征(feature)\n",
    "+ 最后一列，称为标记(label)\n",
    "\n",
    "### 机器学习的基本概念如下\n",
    "> ![机器学习的基本概念图示](./images/机器学习的基本概念.jpg)\n",
    "\n",
    "### 特征向量的表示如下\n",
    "\n",
    "> ![特征向量的表示](./images/特征向量的表示.jpg)\n",
    "\n",
    "### 特征空间与分类\n",
    "\n",
    "> ![特征空间与分类](./images/特征空间与分类.jpg)\n",
    "\n",
    "### 特征可以很抽象\n",
    "\n",
    "> ![特征可以很抽象](./images/特征可以很抽象.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.2 机器学习的主要任务\n",
    "\n",
    "### 机器学习的任务分类\n",
    "\n",
    "+ 1.分类任务，只能有几种确定的结果：\n",
    "  + 1.1 二分类\n",
    "    + 判断是否是垃圾邮件\n",
    "    + 判断发卡有没有风险\n",
    "    + 判断病患是良性肿瘤还是恶性肿瘤\n",
    "    + 判断股票是涨还是跌\n",
    "  + 1.2 多分类\n",
    "    + 数字识别\n",
    "    + 图像识别\n",
    "    + 银行判断发卡的风险评级\n",
    "    + 玩2048游戏，上移下移左移右移\n",
    "    + 多分类任务\n",
    "      + 可以转化为二分类任务\n",
    "      + 只支持二分类的算法可以用来处理多分类任务\n",
    "      + 有些算法天然可以完成多分类任务\n",
    "  + 1.3 多标签分类：一个对象可以划分到多个分类中，最后根据这些分类综合区判断对象\n",
    "+ 2.回归任务：结果是一个**连续数字**的值，而不是类别\n",
    "  + 房屋价格\n",
    "  + 市场分析\n",
    "  + 学生成绩\n",
    "  + 股票价格\n",
    "\n",
    "> 有些算法只能用在分类，有的只能回归，有的都行。`一些情况下回归任务可以转化成分类任务`\n",
    "\n",
    "### 机器学习解决问题的通用套路\n",
    "\n",
    "![机器学习解决问题的通用套路](images/机器学习解决问题的通用套路.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2-3 监督学习、非监督学习、半监督学习和增强学习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 监督学习\n",
    "> 给机器的训练数据拥有“标记”或者“答案”，数据都有标记那一列，除了这一列，其他列表示特征。每一行数据表示一个样本，例如猫狗分类，要告诉机器是猫还是狗。\n",
    "\n",
    "监督学习举例：\n",
    "+ 图像已经拥有了标定信息\n",
    "+ 银行已经积累了一定客户信息和他们信用卡的信用情况\n",
    "+ 医院已经积累了一定的病人信息和他们最终确诊是否患病的情况\n",
    "+ 市场积累了房屋的基本信息和最终成交的金额\n",
    "\n",
    "监督学习主要处理两大类问题:**分类和回归**\n",
    "\n",
    "监督学习涉及的算法：\n",
    "+ K近邻\n",
    "+ 线性回归和多项式回归\n",
    "+ 逻辑回归\n",
    "+ SVM\n",
    "+ 决策树和随机森林\n",
    "\n",
    "很多时候非监督学习的核心是辅助监督学习\n",
    "\n",
    "### 非监督学习\n",
    "\n",
    "> 给机器的训练数据没有任何“标记”或者“答案”\n",
    "\n",
    "非监督学习的意义：**对没有标记的数据进行分类--聚类分析**\n",
    "\n",
    "例如：电商网站给消费群体分类\n",
    "\n",
    "+ **另外一个意义**：对数据进行降维处理\n",
    "+ **特征提取**：信用卡的信用评级和人的胖瘦无关？这时候可以扔掉人的胖瘦数据，进而达到降维目的\n",
    "+ **特征压缩**：不扔掉数据，两组数据有很强的关联性，让二维的点变成一维的点，特这个能压缩使用的主要手段是PCA\n",
    "+ **降维处理的意义**：方便可视化\n",
    "\n",
    "非监督学习还可以进行异常检测\n",
    "\n",
    "### 半监督学习\n",
    "\n",
    "> 一部分数据有“标记”或者“答案”，另一部分数据没有\n",
    "\n",
    "更常见：**各种原因产生的标记缺失**\n",
    "\n",
    "通常`先使用非监督学习的手段对数据进行处理，之后使用监督学习手段做模型的训练和预测`\n",
    "\n",
    "### 增强学习\n",
    "> 根据周围环境的情况，采取行动，根据采取行动的结果，学习行动方式，类似于PID循环\n",
    "\n",
    "**应用**：阿尔法狗，无人驾驶，机器人\n",
    "\n",
    "监督学习和半监督学习依然是基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
